import 'dart:io';

import 'package:dart_bean/generator.dart';

//todo make log file  link ok
//todo show error when converter not work
void main() async {
  prepareTestBeans();
  final projectRoot = Directory('test').parent;
  await Generator.startMain([projectRoot.path, 'test_bean_lib']);
}

void prepareTestBeans() {
  final fromDir = Directory('test_case/ok');
  final toDir = Directory('test_bean_lib');
  if (toDir.existsSync()) toDir.deleteSync(recursive: true);
  fromDir.listSync(recursive: true).forEach((e) {
    final path = e.path.replaceFirst(fromDir.path, '');
    if (path.endsWith('.dart')) {
      final file = File('${toDir.path}$path');
      if (!file.parent.existsSync()) file.parent.createSync(recursive: true);
      file.writeAsStringSync(File(e.path).readAsStringSync());
    }
  });
}
